<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="订单编号" prop="orderNumber"
                :rules="[
                  {required: true, message:'订单编号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.orderNumber" placeholder="请填写订单编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="下单人" prop="payUser.id"
                :rules="[
                  {required: true, message:'下单人不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择下单人"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.payUser.id"
            :limit="1"
            @getValue='(value) => {inputForm.payUser.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/list"
            entityBeanName="userInformation"
            queryEntityUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="下单商品" prop="payGoods.id"
                :rules="[
                  {required: true, message:'下单商品不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择下单商品"
            labelName = 'goodsTitle'
            labelValue = 'id'
            :value = "inputForm.payGoods.id"
            :limit="1"
            @getValue='(value) => {inputForm.payGoods.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'goodsTitle',
              label: '标题'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'goodsTitle',
              label: '标题'
            }
            ]"
            dataListUrl="/lhyg/lgy/goodsdetails/goodsDetails/list"
            entityBeanName="goodsDetails"
            queryEntityUrl="/lhyg/lgy/goodsdetails/goodsDetails/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="支付时间" prop="payDate"
                :rules="[
                  {required: true, message:'支付时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.payDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发货时间" prop="hairDate"
                :rules="[
                  {required: true, message:'发货时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.hairDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="完成时间" prop="completeDate"
                :rules="[
                  {required: true, message:'完成时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.completeDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="快递单号" prop="expressNumber"
                :rules="[
                  {required: true, message:'快递单号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.expressNumber" placeholder="请填写快递单号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="快递名称" prop="expressName"
                :rules="[
                  {required: true, message:'快递名称不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.expressName" placeholder="请填写快递名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="订单状态" prop="orderType"
                :rules="[
                  {required: true, message:'订单状态不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.orderType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('order_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="购买数量" prop="payCount"
                :rules="[
                  {required: true, message:'购买数量不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.payCount" placeholder="请填写购买数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="支付金额" prop="payMoney"
                :rules="[
                  {required: true, message:'支付金额不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.payMoney" placeholder="请填写支付金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="收货地址" prop="receivingAddress.id"
                :rules="[
                  {required: true, message:'收货地址不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择收货地址"
            labelName = 'name'
            labelValue = 'id'
            :value = "inputForm.receivingAddress.id"
            :limit="1"
            @getValue='(value) => {inputForm.receivingAddress.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '姓名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'name',
              label: '姓名'
            }
            ]"
            dataListUrl="/lhyg/lgy/useraddress/userAddress/list"
            entityBeanName="userAddress"
            queryEntityUrl="/lhyg/lgy/useraddress/userAddress/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="支付方式" prop="payType"
                :rules="[
                  {required: true, message:'支付方式不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.payType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('pay_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否售后" prop="isAfterSales"
                :rules="[
                  {required: true, message:'是否售后不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.isAfterSales" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('yes_no')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="线上订单号" prop="orderNumbers"
                :rules="[
                  {required: true, message:'线上订单号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.orderNumbers" placeholder="请填写线上订单号"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          orderNumber: '',
          payUser: {
            id: ''
          },
          payGoods: {
            id: ''
          },
          payDate: '',
          hairDate: '',
          completeDate: '',
          expressNumber: '',
          expressName: '',
          orderType: '',
          payCount: '',
          payMoney: '',
          receivingAddress: {
            id: ''
          },
          payType: '',
          isAfterSales: '',
          remarks: '',
          orderNumbers: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建商品订单表`
        } else if (method === 'edit') {
          this.title = '修改商品订单表'
        } else if (method === 'view') {
          this.title = '查看商品订单表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/lhyggoodsorder/lhygGoodsOrder/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.lhygGoodsOrder)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/lhyggoodsorder/lhygGoodsOrder/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>